package com.jizhi.rabbitmq.forecast;

import com.jizhi.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;

import java.io.IOException;

public class PrefetchingMessages3Test {
	private static final String ACK_QUEUE_NAME = "ack_queue";

	public static void main(String[] args) throws Exception {
		Channel channel = RabbitMqUtils.getChannel();
		// 开启自动确认
		channel.basicConsume(ACK_QUEUE_NAME, false, new DefaultConsumer(channel) {
			@Override
			public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body)
					throws IOException {
				// 限定消费的条数
				System.out.println("消费者3开始处理消息====>" + new String(body, "utf-8"));
				 channel.basicAck(envelope.getDeliveryTag(), false);
			}
		});
	}
}